package com.wicket.okrframework.biz.service.nb;

import com.wicket.okrframework.base.service.dto.common.OrgDeptPositionDto;
import com.wicket.okrframework.biz.service.dto.common.AddDeptPositionDto;
import com.wicket.okrframework.biz.service.dto.req.CheckRemovalObjsReqDto;
import com.wicket.okrframework.biz.service.dto.res.CheckRemovalObjsRespDto;
import com.wicket.okrframework.biz.service.dto.res.OrgInductionRecordDto;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import com.wicket.okrframework.biz.service.dto.req.ImplementClassDeptPositionAddFileReqDto;
import com.wicket.okrframework.biz.service.dto.res.ImplementClassDeptPositionAddFileRespDto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ： 手工接入方法
 * @since 2022/5/28 15:32
 *
 *
 * @version 1.0
 */
@Service
public class NbOrgPosition {
    /**
     * code:collectionRemoveDuplicateData
     * name:M去重职务所属对象（特殊方法）
     * desc:undefined
     **/
    @Trace(operationName = "M去重职务所属对象（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CheckRemovalObjsRespDto checkRemovalObjs(CheckRemovalObjsReqDto reqDto) {
        // TODO ruizhe skai dong ; 2022/6/30 下午11:51:08
        return new CheckRemovalObjsRespDto();
    }
/**
      * code:dataAucClassification
      * name:M1执行分类部门职务新增与存档（特殊方法）
      * desc:undefined
      * gen by moon at 8/10/2022, 3:12:29 AM
      * 
      **/
     @Trace(operationName = "M1执行分类部门职务新增与存档（特殊方法）")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementClassDeptPositionAddFileRespDto implementClassDeptPositionAddFile(ImplementClassDeptPositionAddFileReqDto reqDto) {
         ImplementClassDeptPositionAddFileRespDto retData = new ImplementClassDeptPositionAddFileRespDto();
         List<AddDeptPositionDto> addDeptPositionList = new ArrayList<>();
         List<String> fileDeptPosition = new ArrayList<>();
         Map<String,OrgInductionRecordDto> inducIndex = new HashMap<>();
         Map<String, OrgDeptPositionDto> orgIndex = new HashMap<>();
         for(OrgInductionRecordDto oneInduc : reqDto.getOrgInductionRecordList()){
             inducIndex.put(oneInduc.getEntityId()+oneInduc.getPositionId(),oneInduc);
         }
         for(OrgDeptPositionDto oneDept : reqDto.getOrgDeptPositionList()){
             orgIndex.put(oneDept.getOrgEntityId()+oneDept.getPositionId(),oneDept);
         }
         for(OrgInductionRecordDto oneInduc : reqDto.getOrgInductionRecordList()){
             if(!inducIndex.containsKey(oneInduc.getEntityId()+oneInduc.getPositionId())
             ||orgIndex.containsKey(oneInduc.getEntityId()+oneInduc.getPositionId())){
                 AddDeptPositionDto elm = new AddDeptPositionDto();
                 elm.setEntityId(oneInduc.getEntityId());
                 elm.setPositionId(oneInduc.getPositionId());
                 addDeptPositionList.add(elm);
             }
         }

         for(OrgDeptPositionDto oneDept : reqDto.getOrgDeptPositionList()){
             if(!inducIndex.containsKey(oneDept.getOrgEntityId()+oneDept.getPositionId())
                     ||orgIndex.containsKey(oneDept.getOrgEntityId()+oneDept.getPositionId())){
                 fileDeptPosition.add(oneDept.getOrgPositionRelationshipId());
             }
         }
         retData.setAddDeptPositionList(addDeptPositionList);
         retData.setFileDeptPosition(fileDeptPosition);
        return retData;
      }
    //手工接入方法
}
